﻿using DotNetCore.CAP;
using NewRetail.Application.Core;
using System;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Json;

namespace NewRetail.Application.Worker
{
    public class PosDaySumNotifyMessage
    {
        public string WarehouseId { get; set; }
        public DateTime ChinaDate { get; set; }
    }

    public class DataSyncWrapper
    {
        public string DataType { get; set; }
        public string Payload { get; set; }
    }

    public interface INewRetailEventBus
    {
        Task NotifyPayDaySumCal(PosDaySumNotifyMessage message);
        Task QueueDataSync(DataSyncWrapper message);
        Task NotifyMemberIntergralCal(MemberIntergralCalMessage message);
        Task NotifyWarehouseGoodsCal(WarehouseGoodsCalMessage message);
    }

    [ExposeServices(typeof(INewRetailEventBus))]
    public class NewRetailEventBus : INewRetailEventBus, ITransientDependency
    {
        private readonly ICapPublisher capPublisher;
        private readonly IJsonSerializer jsonSerializer;
        public NewRetailEventBus(ICapPublisher capPublisher, IJsonSerializer jsonSerializer)
        {
            this.capPublisher = capPublisher;
            this.jsonSerializer = jsonSerializer;
        }

        public async Task NotifyPayDaySumCal(PosDaySumNotifyMessage message)
        {
            await this.capPublisher.PublishAsync(MessageTopics.PAY_DAY_SUM_CAL, message);
        }

        public async Task QueueDataSync(DataSyncWrapper message)
        {
            await this.capPublisher.PublishAsync(MessageTopics.DATA_SYNC, message);
        }

        public async Task NotifyMemberIntergralCal(MemberIntergralCalMessage message)
        {
            await this.capPublisher.PublishAsync(MessageTopics.MEMBER_INTERGRAL_CAL, message);
        }

        public async Task NotifyWarehouseGoodsCal(WarehouseGoodsCalMessage message)
        {
            await this.capPublisher.PublishAsync(MessageTopics.WAREHOUSE_GOODS_COST_CAL, message);
        }
    }
}
